package share.download.utils;

import javax.servlet.http.HttpServletRequest;

import share.common.utils.ClientAnalyst;

public class DownloadThreadLimiter {
	String ip;
	static final int ThreadLimit = 5;

	public DownloadThreadLimiter(HttpServletRequest r) {
		ip = new ClientAnalyst(r).getIpAddr();
	}

	public boolean registerNewThread() {
		if(ClientIpTable.registerIP(ip)>ThreadLimit){
//			System.out.println("new thread rejected");
			ClientIpTable.unregisterIP(ip);
			return false;
		}
		return true;
	}
	
	public void unregisterThread(){
		ClientIpTable.unregisterIP(ip);
		//System.out.println("thread unregistered");
	}
	
}
